{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.87b3235150b111be259614083976ebd0.315360000.1964069682.282335-25863383', 'expires_in': 2592000, 'session_key': '9mzdCPPW9hhUuamT8TQSz7hwhYddhY0Ea4Hrp96w7qjBpI7QsrX7krT5pYdg6nXH/rby1JkkQKBcjYZ6qPfPCZu4nYadhw==', 'access_token': '24.37d28b62a7ec10da1fc36ed9820a8801.2592000.1651301682.282335-25863383', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage brain_multi_ object_detect wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': '8e4c52cd92f1553dcc572089117f3365'}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "import requests \n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?'\n",
    "payload = {\n",
    "    'grant_type':'client_credentials',\n",
    "    'client_id':'z8KCG60rMKYWOSO1gZxFByIT',\n",
    "    'client_secret':'eTwKkWeEgfMN1w3aSLWVdHhjuyIwchL8'\n",
    "}\n",
    "response = requests.get(host,params=payload)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.37d28b62a7ec10da1fc36ed9820a8801.2592000.1651301682.282335-25863383'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ruiqian_AT = response.json()['access_token']\n",
    "ruiqian_AT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'result': [{'name': '狮子猫', 'score': '0.479261', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E7%8B%AE%E5%AD%90%E7%8C%AB/4340094', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/5882b2b7d0a20cf431ada5c49c415c36acaf2edd33dd', 'description': '狮子猫又称临清狮子猫，主要产于山东省临清市，是由蓝眼睛的波斯猫与黄眼睛的鲁西本地狸猫杂交繁育出来的变异品种。在诸多品种中，以一只蓝眼、一只黄眼，白毛拖地的雪狮子最为珍贵。人们称其为“鸳鸯眼狮猫”。临清狮子猫的培育形成与伊斯兰教的传人和运河的开通有密切的关系。到了明代，伴随着明朝与波斯的交往，波斯猫也在这里安家落户，加之波斯猫喜食羊的肝肾，便很快在回民家中繁衍开来。纯种临清狮子猫的颈、背部毛长达4—5厘米，站姿犹如狮子。也有黑白相间毛色的品种，但以纯白的较为珍贵。狮子猫身体强壮、抗病力强、耐寒冷、善于捕鼠。性格温婉，不喜欢陌生人，对主人有较强的依赖性。临清狮子猫因其独特的形象，一直是宠物市场上的高价极品猫。'}}, {'name': '土耳其梵猫', 'score': '0.436943', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E5%9C%9F%E8%80%B3%E5%85%B6%E6%A2%B5%E7%8C%AB/4630925', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/dcc451da81cb39dbc04c0851da160924ab18302c', 'description': '土耳其梵猫，英文名：Turkish Van，原产土耳其国，长型而结实体型，中长度长毛，被毛白而发亮，毛质如同丝绸般十分光滑。全身除头耳部和尾部有乳黄色或浅褐色的斑纹外，没有一根杂毛，外表极为美丽和可爱。头部呈宽广的楔形；耳朵小；眼睛为大型椭圆形。性格聪明、机敏、活泼、喜欢玩耍、攀爬。叫声甜美悦耳，对人友善，是极适宜家庭饲养的优良品种。土耳其梵猫是土耳其国宝，起源于土耳其的梵湖地区，是由土耳其安哥拉猫突变而成的，严格说是安哥拉猫的一个品系。'}}, {'name': '波斯猫', 'score': '0.0270563', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E6%B3%A2%E6%96%AF%E7%8C%AB/585', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/cc11728b4710b9123e0206d7cefdfc03934522dc', 'description': '波斯猫(Persian cat)是以阿富汗的土种长毛猫和土耳其的安哥拉长毛猫为基础，在英国经过100多年的选种繁殖，于1860年诞生的一个品种。波斯猫是最常见的长毛猫，波斯猫有一张讨人喜爱的面庞，长而华丽的背毛，优雅的举止，故有“猫中王子”、“王妃”之称，是世界上爱猫者最喜欢的纯种猫之一，占有极其重要的地位。'}}, {'name': '土耳其安哥拉猫', 'score': '0.0239405', 'baike_info': {}}, {'name': '布偶猫', 'score': '0.00589296', 'baike_info': {'baike_url': 'http://baike.baidu.com/item/%E5%B8%83%E5%81%B6%E7%8C%AB/642121', 'image_url': 'https://bkimg.cdn.bcebos.com/pic/4034970a304e251fc3ec88c8af86c9177f3e53e2', 'description': '布偶猫是猫中较大、较重的一种。它的头呈V形，眼大而圆，被毛丰厚，四肢粗大，尾长，身体柔软，多为三色或双色猫。布偶猫抱起来像软绵绵的布偶，而且对人非常友善。它性格大胆，不知道什么叫恐惧，而且对疼痛的忍耐性相当强，常被误认为缺乏疼痛感，因此很能容忍孩子的玩弄，是非常理想的家庭宠物。'}}, {'name': '四川简州猫', 'score': '0.00299642'}], 'log_id': 1509424021080379976}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "动物识别\n",
    "'''\n",
    "\n",
    "request_url = \" https://aip.baidubce.com/rest/2.0/image-classify/v1/animal\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('dongwu.jpg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "# 2.酬载准备\n",
    "params = {\"image\":img}\n",
    "payload={\n",
    "    'access_token': ruiqian_AT,\n",
    "    'image':img,\n",
    "    'baike_num':5\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
